//////////////////////////////////////////////////////////////////////
// order from left to right, index base on 1
// set index 8 and 15 to 1 by setBit, hex data as follow
// index: 1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16
// value: 0  0  0  0  0  0  0  1  0  0  0  0  0  0  1  0
// bit array data: 0x01, 0x02
//////////////////////////////////////////////////////////////////////

#ifndef BIT_ARRAY_H
#define BIT_ARRAY_H

namespace suxw
{
    class BitArray
    {

    public:
        BitArray();
        BitArray(int nBitsCount);
        ~BitArray();

        //set valid bit count
        bool setBitsCount(unsigned int nBitsCount);
        //get valid bit count
        unsigned int getBitsCount();
        //set bit value
        bool setBit(unsigned int index, bool value);
        //get bit value
        bool getBit(unsigned int index);
        //clear bit array information
        void clear();
        //get address of bit array buffer
        unsigned char* getBitArray();
        //get size of bit arary
        int size();

        //self test function
        static bool main(int argc, char **argv);

    private:
        //calculate buffer size by valid bit count
        int calcSize(unsigned int nBitsCount);

    private:
        //valid bit count
        unsigned int m_nBitsCount;
        //address of bit array buffer
        unsigned char *m_pcBitBuf;
    };
}

#endif //BIT_ARRAY_H
